package com.cby.operation.common.http.ssl

import java.security.KeyManagementException
import java.security.NoSuchAlgorithmException
import java.security.SecureRandom
import javax.net.ssl.SSLContext
import javax.net.ssl.SSLSocketFactory
import javax.net.ssl.TrustManager

/**
 * Description:HttpsSSLSocketFactory
 *
 * @author 陈宝阳
 * @create 2020/8/3 14: 46
 */
object HttpsSSLSocketFactory {
    fun factory(): SSLSocketFactory {
        var sslContext: SSLContext? = null
        try {
            sslContext = SSLContext.getInstance("SSL")
        } catch (e: NoSuchAlgorithmException) {
            e.printStackTrace()
        }
        val tm = arrayOf<TrustManager>(HttpsX509TrustManager())
        try {
            sslContext!!.init(null, tm, SecureRandom())
        } catch (e: KeyManagementException) {
            e.printStackTrace()
        }
        return sslContext!!.socketFactory
    }
}